package list.ittest.work.B_Controller;

import list.ittest.work.C_Service.StudentService;
import list.ittest.work.E_Domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentController {
    StudentService ss = new StudentService();

    public void strat() {
        Scanner sc = new Scanner(System.in);

        ol:
        while (true){
            System.out.println("--------欢迎来到 <学生> 管理系统--------");
            System.out.println("请输入您的选择: 1.添加学生  2.删除学生  3.修改学生  4.查看学生  5.退出");
            String choice =sc.next();
            switch (choice){
                case "1":
                    //System.out.println("添加学生");
                    addStudent();
                    break;
                case "2":
                    //System.out.println("删除学生");
                    deleteStudent();
                    break;
                case "3":
                    //System.out.println("修改学生");
                    updateStudent();
                    break;
                case "4":
                    //System.out.println("查看学生");
                    lookStudent();
                    break;
                case "5":
                    System.out.println("感谢使用学生管理系统，欢迎下次光临！");
                    break ol;
                default:
                    System.out.println("你输入的有误，请重新输入");
                    break;
            }
        }
    }
    //修改学生
    private void updateStudent() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要修改的学生学号");
        String id =sc.next();
        boolean flag = ss.cheakId(id);
        if(flag==true){
            System.out.println("不好意思，该学号学生不存在");
            return;
        }
        System.out.println("请输入想要修改的学生姓名");
        String name = sc.next();
        System.out.println("请输入想要修改的学生年龄");
        int age = sc.nextInt();
        System.out.println("请输入想要修改的学生生日");
        String birthday = sc.next();
        Student s = new Student();
        s.setId(id);
        s.setName(name);
        s.setAge(age);
        s.setBirthday(birthday);
        ss.updateStudent(s);
        System.out.println("修改成功");



    }

    //删除学生
    private void deleteStudent() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要删除的学生学号");
        String id =sc.next();
        boolean flag =ss.deleteStudent(id);
        if(flag==false){
            System.out.println("删除失败，查无此人");
        }else{
            System.out.println("删除成功！");
        }
    }

    //查找学生
    private void lookStudent() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要查找的学生学号");
        String id =sc.next();
        ArrayList<Student> list = ss.lookStudent();
        if(list.size()==0){
            System.out.println("查无信息");
            return;
        }
        System.out.println("学号\t\t姓名\t\t年龄\t\t生日");
        for (int i = 0; i < list.size(); i++) {
            Student s =list.get(i);
            System.out.println(s.getId()+"\t\t"+s.getName()+"\t\t"+s.getAge()+"\t\t\t"+s.getBirthday());
        }
    }

    //添加学生
    private void addStudent() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要添加学生学号");
        String id =sc.next();
        System.out.println("请输入你要添加学生姓名");
        String name =sc.next();
        System.out.println("请输入你要添加学生年龄");
        int age =sc.nextInt();
        System.out.println("请输入你要添加学生生日");
        String birthday = sc.next();
        Student stu = new Student();
        stu.setId(id);
        stu.setName(name);
        stu.setAge(age);
        stu.setBirthday(birthday);
        ss.addStudent(stu);
        System.out.println("添加成功");

    }
}
